FROM php:7.0-fpm-alpine3.7


# 时区设置
ENV TIMEZONE Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && echo $TIMEZONE > /etc/timezone

# 查询 alpine 版本 && 设置镜像源
RUN source /etc/os-release && printf "\
http://mirrors.aliyun.com/alpine/v${VERSION_ID%.*}/main\n\
http://mirrors.aliyun.com/alpine/v${VERSION_ID%.*}/community\n\
" > /etc/apk/repositories

# re2c PHP词法解析器
ENV PHPIZE_DEPS autoconf g++ gcc make file re2c

# 更新最新本地镜像源
RUN apk update

#创建运行账号,指定uid与pid
RUN addgroup -S nginx -g 1001 \
    && adduser -D -S -h /var/cache/nginx -s /sbin/nologin -u 1001 -G nginx nginx
# 安装基础库
RUN apk add openssl

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
\
# PHP GD
&& apk add --no-cache libpng libjpeg-turbo freetype libxpm \
&& apk add --no-cache --virtual .build-tmp libpng-dev libjpeg-turbo-dev libxpm-dev freetype-dev \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-xpm-dir=/usr/include/ \
&& docker-php-ext-install gd \
\
# PHP mysqli
&& docker-php-ext-install mysqli \
\
# PHP pdo_mysql
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install pdo_mysql \
\
# PHP bcmath
&& docker-php-ext-install bcmath \
\
# PHP opcache
&& docker-php-ext-install opcache \
# PHP sockets
&& docker-php-ext-install sockets \
# PHP mbstring
&& apk add --no-cache oniguruma \
&& apk add --no-cache --virtual .build-tmp oniguruma-dev \
&& docker-php-ext-install mbstring \
# PHP zip
&& apk add --no-cache libzip \
&& apk add --no-cache --virtual .build-tmp libzip-dev \
&& docker-php-ext-install zip

# 下面几个扩展依赖网络，容易出错
# 这里采用单独RUN命令，提交新的镜像(目的: 利用上面构建好的cache，避免重头build)

# PHP redis
RUN pecl install redis-5.3.1  && docker-php-ext-enable redis

# PHP amqp 扩展
RUN apk add --no-cache rabbitmq-c \
&& apk add --no-cache --virtual .build-tmp rabbitmq-c-dev \
&& pecl install amqp \
&& docker-php-ext-enable amqp

# composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer
# use aliyun composer
RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 安装 yaconf
RUN pecl install yaconf && docker-php-ext-enable yaconf

# 安装 yar
RUN apk add curl-dev \
&& pecl install msgpack && docker-php-ext-enable msgpack \
&& pecl install https://pecl.php.net/get/yar-2.0.4.tgz && docker-php-ext-enable yar

# 安装 yaf, 版本太高会导致类无法自动加载
RUN pecl install https://pecl.php.net/get/yaf-3.0.7.tgz && docker-php-ext-enable yaf


# mongodb
RUN pecl install https://pecl.php.net/get/mongodb-1.5.3.tgz && docker-php-ext-enable mongodb

# 清除构建包，减少镜像体积
RUN apk del .build-deps .build-tmp

# 设置工作目录
RUN mkdir /data
WORKDIR /data
